const path = require('path');
const I18nWebpackPlugin = require('@fiber/i18n-webpack-plugin');
const devServer = require("./config/devServer.js");
const V5PcPlugin = require('./config/plugin/V5PcPlugin.js');
const DistInitPlugin = require('./config/plugin/DistInitPlugin.js');
const DistEndPlugin = require('./config/plugin/DistEndPlugin.js');
const FailedPlugin = require('./config/plugin/FailedPlugin.js');

const alias = require('./config/alias.js');
var options = process.argv;
console.log(options);
const ParamsUtils = require("./config/utils/ParamsUtils.js");

let vueConfig = {
    lintOnSave: false, // eslint关闭
    productionSourceMap: false, // map 映射
    assetsDir: "static",
    publicPath: "./",
    transpileDependencies: ["./src"],
    configureWebpack: {
        plugins: [
            new I18nWebpackPlugin({
                inject: false
            }),
            new DistInitPlugin(),
            new DistEndPlugin(),
            new V5PcPlugin(),
            // new ShopPlugin({
            //     auto:true
            // }),// 商城插件不能与AutoCompilePlugin同时使用，两边都会重写dist下目录
            new FailedPlugin(),
        ],
        output: {
            filename: `static/js/[name].min.js?[hash:5]`,
            chunkFilename: `static/js/[name].min.js?[hash:5]`
        },
        // optimization: {
        //     runtimeChunk: 'single',
        //     splitChunks: {
        //         cacheGroups: {
        //             vendor: {
        //                 test: /[\\/]node_modules[\\/]/,
        //                 name: 'vendors',
        //                 chunks: 'all'
        //             }
        //         }
        //     }
        // },
        resolve: {
            alias: alias
        }
    },
    chainWebpack(config){
        if (process.env.NODE_ENV === 'production') {
            config.plugins.delete('preload-index');
            config.plugin('extract-css')
                .tap(args => [{
                    filename: `static/css/[name].css?[hash:5]`,
                    chunkFilename: `static/css/[name].css?[hash:5]`
                }])
        }
    },
    outputDir: ParamsUtils.getOutputDir(),
    devServer: devServer,
    pages: {
        index: 'src/main.js',
    }
};

module.exports = vueConfig;
